package com.google.code.wicket.auth.component.marker;

import java.util.Collection;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.Session;

import com.google.code.wicket.auth.component.value.provider.session.SessionLoginProvider;

/**
 * Deals with components by setting
 * {@link Component#setVisibilityAllowed(boolean)} to false. Redirects to a
 * login page if user isn't logged in yet.
 * 
 * @param <S>
 *            session type
 * @param <T>
 *            the privilege type
 * @param <P>
 *            login page type
 */
public class SessionBasedComponentHideMarker<S extends Session, T, P extends Page>
        extends SessionBasedMarkerSupportWithLoginPage<S, T, P> {

    /**
     * Constructor with a login provider, a privilege type and a login page.
     * 
     * @param loginProvider
     * @param privilegeType
     * @param loginPage
     */
    public SessionBasedComponentHideMarker(
            final SessionLoginProvider<S> loginProvider,
            final Class<T> privilegeType, final Class<P> loginPage) {
        super(loginProvider, privilegeType, loginPage);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean doHandleMissingValuesForLoggedInSession(final S session,
            final Component component, final Collection<T> missingValues) {
        component.setVisibilityAllowed(false);
        return true;
    }

}
